package com.yswl.yeeduo.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yswl.yeeduo.R;
import com.yswl.yeeduo.ui.bean.DetailMoneyBean;
import com.yswl.yeeduo.view.listview.BaseListViewAdapter;

public class DeitalMoneyAdapter extends BaseListViewAdapter<DetailMoneyBean> {

	LayoutInflater mInflater;

	public DeitalMoneyAdapter(Context context) {
		super(context);
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.deitalmoney_list_item, null);
			viewHolder.title = (TextView) convertView.findViewById(R.id.user_name_tv);
			viewHolder.share_tv = (TextView) convertView.findViewById(R.id.share_obtain_money_tv);
			viewHolder.read_tv = (TextView) convertView.findViewById(R.id.read_obtain_money_tv);
			viewHolder.total_tv = (TextView) convertView.findViewById(R.id.obtain_money_count_tv);
			viewHolder.state_tv = (LinearLayout) convertView.findViewById(R.id.share_state_tv);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		DetailMoneyBean bean = getItem(position);
		viewHolder.title.setText(bean.title);
		viewHolder.share_tv.setText(bean.shareMoney+"");
		viewHolder.read_tv.setText(bean.readMoney+"");
		if (bean.status == 0) {
			viewHolder.state_tv.setBackgroundResource(R.drawable.detail_money_yes);
		} else {
			viewHolder.state_tv.setBackgroundResource(R.drawable.detail_money_no);
		}
		double totalMoney = bean.shareMoney + bean.readMoney;
		viewHolder.total_tv.setText(String.format("%.2f",totalMoney));

		return convertView;
	}

	private static class ViewHolder {
		public TextView title;
		public TextView share_tv;
		public TextView read_tv;
		public LinearLayout state_tv;
		public TextView total_tv;
	}

}
